#include "list.h"
/**
 * @brief 判断链表是否有环
 *
 * @param head 链表的第一个结点
 * @return true 有环
 * @return false 无环
 */

//题目来源:https://leetcode-cn.com/problems/linked-list-cycle/
bool hasCycle(ListNode* head) {
  if (head == nullptr) {
    return false;
  }
  ListNode* fast = head;
  ListNode* slow = head;

  while (fast && fast->next_) {
    fast = fast->next_->next_;
    slow = slow->next_;

    if (slow == fast) {
      return true;
    }
  }

  return false;
}